﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.FxCop.Sdk;

namespace FxCopContrib.TestHarness
{
    public class ProblemPrototype
    {
        private ProblemPrototype()
        {
            Certainty = null;
            FixCategory = null;
            Resolution = ResolutionPrototype.Default;
            SourceFile = "*";
            SourceLine = null;
            Id = "*";
            MessageLevel = null;
            Count = 1;
        }

        public static ProblemPrototype Default
        {
            get
            {
                return new ProblemPrototype();
            }
        }

        public static ProblemPrototype WithResulutionName(string resolutionName)
        {
            var result = ProblemPrototype.Default;
            result.Resolution = new ResolutionPrototype() { Name = resolutionName };
            return result;
        }

        internal bool Matches(Microsoft.FxCop.Sdk.Problem p)
        {
            bool result = true;
            if (Certainty.HasValue)
            {
                result &= (Certainty.Value == p.Certainty);
            }

            if (FixCategory.HasValue)
            {
                result &= (FixCategory.Value == p.FixCategory);
            }

            if (MessageLevel.HasValue)
            {
                result &= (MessageLevel.Value == p.MessageLevel);
            }

            if (Resolution != null)
            {
                result &= Resolution.Matches(p.Resolution); 
            }

            if (Id != null && !Id.Equals("*", StringComparison.OrdinalIgnoreCase))
            {
                result &= string.Equals(Id, p.Id, StringComparison.OrdinalIgnoreCase);
            }

            if (SourceFile != null && !SourceFile.Equals("*", StringComparison.OrdinalIgnoreCase))
            {
                result &= string.Equals(SourceFile, p.SourceFile, StringComparison.OrdinalIgnoreCase);
            }

            if (SourceLine.HasValue)
            {
                result &= (SourceLine.Value == p.SourceLine);
            }

            return result;
        }

            
        public  int? Certainty { get; set; }

        public Microsoft.VisualStudio.CodeAnalysis.Extensibility.FixCategories? FixCategory { get; set; }

        public string Id { get; set; }

        public Microsoft.VisualStudio.CodeAnalysis.Extensibility.MessageLevel? MessageLevel { get; set; }

        public ResolutionPrototype Resolution { get; set; }

        public string SourceFile { get; set; }

        public int? SourceLine { get; set; }

        public int Count { get; set; }
    }
}
